package com.zr.daoImpl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.zr.dao.LoginDaocy;
import com.zr.model.User;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONObject;

public class LoginDaoImplcy implements LoginDaocy{
	public User getUserByUnameAndUpsw(String uname, String upsw) {
		//创建用户对象
		User p =new User();
		//创建sql语句
		StringBuffer sql=new StringBuffer();
		sql.append(" SELECT `user`.uid,`user`.uname,`user`.upsw,`user`.tid,`user`.aid,`user`.sid,`user`.rid  FROM `user`");
		sql.append(" WHERE `user`.uname=? And `user`.upsw=?"); 
		//链接数据库
		Connection con=JDBCUtil.getConnection();
		try {
			//获取预编译对象
			PreparedStatement pst =con.prepareStatement(sql.toString());
			pst.setString(1, uname);
			pst.setString(2, upsw);
			ResultSet rs=pst.executeQuery();
			if(rs.next()){
				p.setUname(rs.getString("uname"));
				p.setUpsw(rs.getString("upsw"));
				p.setUid(rs.getInt("uid"));
				p.setTid(rs.getInt("tid"));
				p.setAid(rs.getInt("aid"));
				p.setSid(rs.getInt("sid"));
				p.setRid(rs.getInt("rid"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return p;
	}
}
